home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / gemtrm12.zoo / forms.c next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  9.4 KB  |  337 lines

  1. /*********************************************************************
  2.  * GEMTERM V1.2
  3.  * 1992 by Martin F. Gergeleit
  4.  * placed in the public domain
  5.  *
  6.  * GEMTERM COMES WITH ABSOLUTELY NO WARRANTY, NOR WILL I BE LIABLE FOR ANY
  7.  * DAMAGES INCURRED FROM THE USE OF IT. USE ENTIRELY AT YOUR OWN RISK!!!
  8.  *********************************************************************/
  9.  
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <gemfast.h>
  13. #include <osbind.h>
  14. #include <mintbind.h>
  15. #include "txtwin.h"
  16. #include "gemterm.h"
  17.  
  18. #ifdef DEBUG
  19. #include <stdio.h>
  20. #endif
  21.  
  22. extern int handle;
  23. extern char path[], file[];
  24. extern int default_font;
  25. extern int default_height;
  26. extern int max_font;
  27. extern short got_font;
  28. extern OBJECT *rs_trindex[];
  29. extern int tty;
  30. extern short tty_used;
  31. extern char args[];
  32. extern char default_cwd[];
  33. extern short default_pers;
  34. extern short default_keep;
  35. extern short default_conv;
  36. extern short do_dialog;
  37.  
  38. static char c_line[136];
  39.  
  40. do_select_dialog(win, cmd_line)
  41. txt_win *win;
  42. char **cmd_line;
  43. {
  44. int tmpx, tmpy, tmpw, tmph;
  45. int exit_button;
  46. int font_index;
  47. char font_name[32];
  48. int i, j, ret;
  49. int startobj;
  50. OBJECT *tree;
  51. TEDINFO *tname, *targs, *tdir, *tlines, *tcols, *thist;
  52.  
  53. #ifdef DEBUG
  54.   fprintf(stderr, "do_select_dialog starts\n");
  55. #endif
  56.  
  57.   tree = rs_trindex[0];
  58.   tname = (TEDINFO *)tree[TNAME].ob_spec;
  59.   targs = (TEDINFO *)tree[TARGS].ob_spec;
  60.   tdir = (TEDINFO *)tree[TDIR].ob_spec;
  61.   tlines = (TEDINFO *)tree[TLINES].ob_spec;
  62.   tcols = (TEDINFO *)tree[TCOLS].ob_spec;
  63.   thist = (TEDINFO *)tree[THIST].ob_spec;
  64.  
  65.   tree[BPROG].ob_state |= SELECTED;
  66.   tree[TNAME].ob_state &= ~DISABLED;
  67.   tree[TARGS].ob_state &= ~DISABLED;
  68.   tree[TDIR].ob_state &= ~DISABLED;
  69.   tree[BKEEP].ob_state &= ~DISABLED;
  70.   tree[BTERM].ob_state &= ~SELECTED;
  71.   tree[BPTY].ob_state &= ~SELECTED;
  72.   tree[BOK].ob_state &= ~SELECTED;
  73.   tree[BCANCEL].ob_state &= ~SELECTED;
  74.   tree[BSAVE].ob_state &= ~SELECTED;
  75.  
  76.   if (default_pers)
  77.     tree[BPERS].ob_state |= SELECTED;
  78.   else
  79.     tree[BPERS].ob_state &= ~SELECTED;
  80.  
  81.   if (default_keep)
  82.     tree[BKEEP].ob_state &= ~SELECTED;
  83.   else
  84.     tree[BKEEP].ob_state |= SELECTED;
  85.  
  86.   if (default_conv)
  87.     tree[BSCONV].ob_state |= SELECTED;
  88.   else
  89.     tree[BSCONV].ob_state &= ~SELECTED;
  90.  
  91.   win->real_pty = win->my_pty;
  92.   if (tty_used)
  93.     tree[BTERM].ob_state |= DISABLED;
  94.   else
  95.     tree[BTERM].ob_state &= ~DISABLED;
  96.  
  97.   for (font_index = 1; font_index <= max_font ; font_index++) {
  98.     if (default_font == vqt_name(handle, font_index, font_name))
  99.       break;
  100.   }
  101.  
  102.   if (*cmd_line == 0) {
  103.     strcpy(c_line, path);
  104.     for (i = 0; c_line[i] != '\0'; i++)
  105.       if (c_line[i] == '*')
  106.         c_line[i] = '\0';
  107.     strcat(c_line, file);
  108.     *cmd_line = c_line;
  109.   }
  110.   strncpy(tname->te_ptext, *cmd_line, tname->te_txtlen);
  111.   tname->te_ptext[tname->te_txtlen-1] = '\0';
  112.  
  113.   strncpy(targs->te_ptext, &args[1], targs->te_txtlen);
  114.   targs->te_ptext[targs->te_txtlen-1] = '\0';
  115.  
  116.   strncpy(tdir->te_ptext, default_cwd, tdir->te_txtlen);
  117.   tdir->te_ptext[tdir->te_txtlen-1] = '\0';
  118.  
  119.   if (do_dialog) {
  120.    form_center(tree, &tmpx, &tmpy, &tmpw, &tmph);
  121.    form_dial(FMD_START, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  122.  
  123.    objc_draw(tree, SELECT, 8, tmpx, tmpy, tmpw, tmph);
  124.    draw_font(font_name);
  125.  
  126.    startobj = TARGS;
  127.    while ((exit_button = form_do(tree, startobj)) != BOK) {
  128.     switch (exit_button) {
  129.     case BPROG:
  130.       objc_change(tree, TNAME, 0, tmpx, tmpy, tmpw, tmph, 
  131.                   tree[TNAME].ob_state & ~DISABLED, 1);
  132.       objc_change(tree, TARGS, 0, tmpx, tmpy, tmpw, tmph, 
  133.                   tree[TARGS].ob_state & ~DISABLED, 1);
  134.       objc_change(tree, TDIR, 0, tmpx, tmpy, tmpw, tmph, 
  135.                   tree[TDIR].ob_state & ~DISABLED, 1);
  136.       objc_change(tree, BKEEP, 0, tmpx, tmpy, tmpw, tmph, 
  137.                   tree[BKEEP].ob_state & ~DISABLED, 1);
  138.       startobj = TARGS;
  139.       win->real_pty = win->my_pty;
  140.       break;
  141.     case BTERM:
  142.       if (tty_used)
  143.         break;
  144.       objc_change(tree, TNAME, 0, tmpx, tmpy, tmpw, tmph, 
  145.                   tree[TNAME].ob_state | DISABLED, 1);
  146.       objc_change(tree, TARGS, 0, tmpx, tmpy, tmpw, tmph, 
  147.                   tree[TARGS].ob_state | DISABLED, 1);
  148.       objc_change(tree, TDIR, 0, tmpx, tmpy, tmpw, tmph, 
  149.                   tree[TDIR].ob_state | DISABLED, 1);
  150.       objc_change(tree, BKEEP, 0, tmpx, tmpy, tmpw, tmph, 
  151.                   tree[BKEEP].ob_state | DISABLED, 1);
  152.       startobj = TLINES;
  153.       win->real_pty = tty;
  154.       break;
  155.     case BPTY:
  156.       objc_change(tree, TNAME, 0, tmpx, tmpy, tmpw, tmph, 
  157.                   tree[TNAME].ob_state | DISABLED, 1);
  158.       objc_change(tree, TARGS, 0, tmpx, tmpy, tmpw, tmph, 
  159.                   tree[TARGS].ob_state | DISABLED, 1);
  160.       objc_change(tree, TDIR, 0, tmpx, tmpy, tmpw, tmph, 
  161.                   tree[TDIR].ob_state | DISABLED, 1);
  162.       objc_change(tree, BKEEP, 0, tmpx, tmpy, tmpw, tmph, 
  163.                   tree[BKEEP].ob_state | DISABLED, 1);
  164.       startobj = TLINES;
  165.       win->real_pty = win->my_pty;
  166.       break;
  167.     case TNAME:
  168.       form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  169.       fsel_input(path, file, &i);
  170.       if (i) {
  171.         strcpy(c_line, path);
  172.         for (i = 0; c_line[i] != '\0'; i++)
  173.       if (c_line[i] == '*')
  174.             c_line[i] = '\0';
  175.     strcat(c_line, file);
  176.     *cmd_line = c_line;
  177.         strncpy(tname->te_ptext, *cmd_line, tname->te_txtlen);
  178.         tname->te_ptext[tname->te_txtlen-1] = '\0';
  179.       }
  180.       form_dial(FMD_START, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  181.       objc_draw(tree, SELECT, 8, tmpx, tmpy, tmpw, tmph);
  182.       draw_font(font_name);
  183.       break;
  184.     case PFONT:
  185.       if (font_index < max_font) {
  186.         font_index++;
  187.         got_font = TRUE;
  188.       }
  189.       default_font = vqt_name(handle, font_index, font_name);
  190.       default_font = vst_font(handle, default_font);
  191.       default_height = vst_point(handle, default_height, &ret,&ret,&ret,&ret);
  192.       draw_font(font_name);
  193.       break;
  194.     case TDIR:
  195.       form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  196.       fsel_input(default_cwd, "", &i);
  197.       if (i) {
  198.         for (i = 0; default_cwd[i] != '\0'; i++)
  199.       if (default_cwd[i] == '*')
  200.             default_cwd[i] = '\0';
  201.         strncpy(tdir->te_ptext, default_cwd, tdir->te_txtlen);
  202.         tdir->te_ptext[tdir->te_txtlen-1] = '\0';
  203.       }
  204.       form_dial(FMD_START, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  205.       objc_draw(tree, SELECT, 8, tmpx, tmpy, tmpw, tmph);
  206.       draw_font(font_name);
  207.       break;
  208.     case MFONT:
  209.       got_font = TRUE;
  210.       if (font_index > 1)
  211.         font_index--;
  212.       default_font = vqt_name(handle, font_index, font_name);
  213.       vst_font(handle, default_font);
  214.       default_height = vst_point(handle, default_height, &ret, &ret,
  215.                                 &ret, &ret);
  216.       draw_font(font_name);
  217.       break;
  218.     case PSIZE:
  219.       got_font = TRUE;
  220.       for (i = 1; i < 32; i++) {
  221.         if ((j = vst_point(handle, i,&ret,&ret,&ret,&ret)) > default_height) {
  222.       default_height = j;
  223.       break;
  224.     }
  225.       }
  226.       draw_font(font_name);
  227.       break;
  228.     case MSIZE:
  229.       got_font = TRUE;
  230.       for (i = 31; i > 0; i--) {
  231.         if ((j = vst_point(handle, i,&ret,&ret,&ret,&ret)) < default_height) {
  232.       default_height = j;
  233.       break;
  234.     }
  235.       }
  236.       draw_font(font_name);
  237.       break;
  238.     case BCANCEL:
  239.       form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  240.       return -1;
  241.     case BSAVE:
  242.       form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  243.       return 0;
  244.     }
  245.    }
  246.   } /* if do_dialog */
  247.   
  248.   default_pers = win->persistent = ((tree[BPERS].ob_state & SELECTED) != 0);
  249.   default_conv = win->backslash_conv = ((tree[BSCONV].ob_state & SELECTED) != 0);
  250.   default_keep = win->keep_on_exit = ((tree[BKEEP].ob_state & SELECTED) == 0);
  251.  
  252.   if ((tree[BTERM].ob_state & SELECTED) || (tree[BPTY].ob_state & SELECTED))
  253.     *cmd_line = 0;
  254.  
  255.   strcpy(&args[1], targs->te_ptext);
  256.   *args = strlen(targs->te_ptext);
  257.  
  258.   win->lines = atoi(tlines->te_ptext);
  259.   if (win->lines < MIN_LINES)
  260.     win->lines = MIN_LINES;
  261.   if (win->lines > MAX_LINES)
  262.     win->lines = MAX_LINES;
  263.  
  264.   win->cols = atoi(tcols->te_ptext);
  265.   if (win->cols < MIN_COLS)
  266.     win->cols = MIN_COLS;
  267.   if (win->cols > MAX_COLS)
  268.     win->cols = MAX_COLS;
  269.  
  270.   win->hist_size = atoi(thist->te_ptext) * 1024;
  271.  
  272.   form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
  273.   
  274.   return 1;
  275.  
  276. #ifdef DEBUG
  277.   fprintf(stderr, "do_select_dialog ends\n");
  278. #endif
  279. }
  280.  
  281. char *my_itoa(n)
  282. register unsigned long n;
  283. {
  284. static char buffer[10];
  285. register char *p = buffer;
  286.  
  287.   do  {
  288.     *p++ = "0123456789"[n % 10];
  289.   } while((n /= 10) > 0);
  290.  
  291.   *p = '\0';
  292.   return(strrev(buffer));
  293. }
  294.  
  295. draw_font(font_name)
  296. char *font_name;
  297. {
  298. char str[40];
  299. int temp[4];
  300. int x, y, w, h, ret;
  301. int fw, fh;
  302. OBJECT *tree;
  303.  
  304. #ifdef DEBUG
  305.   fprintf(stderr, "draw_font starts\n");
  306. #endif
  307.  
  308.   tree = rs_trindex[0];
  309.  
  310.   strcpy(str, my_itoa(default_height));
  311.   strcat(str, "p ");
  312.   strcat(str, font_name);
  313.  
  314.   objc_offset(tree, BFONT, &x, &y);
  315.   w = tree[BFONT].ob_width;
  316.   h = tree[BFONT].ob_height;
  317.   vsf_interior(handle,0);
  318.   vsf_style(handle,8);
  319.   vsf_color(handle,0);
  320.   vst_font(handle, default_font);
  321.   vst_point(handle, default_height, &ret,&ret,&fw,&fh);
  322.   vst_alignment(handle, 0, 5, &ret, &ret);
  323.   set_clip(x, y, w, h);
  324.  
  325.   temp[0] = x;
  326.   temp[1] = y;
  327.   temp[2] = x + w - 1;
  328.   temp[3] = y + h - 1;
  329.   v_bar(handle,temp);
  330.  
  331.   v_gtext(handle, x + (w - fw*strlen(str))/2, y + (h - fh)/2, str);
  332.  
  333. #ifdef DEBUG
  334.   fprintf(stderr, "draw_font ends\n");
  335. #endif
  336. }
  337.